<template>
  <div>
    <template v-if="detailsItem.assessmentStatus != 1 && detailsItem.resultVOS.length != 0">
      <div class="desc">
        <div class="big_title">民主测评结果计票单</div>
        <div class="little_title">
          {{ detailsItem.assessmentSecondTitle }}
          <!-- {{ searchParamsTypeName }}成员 -->
        </div>
        <div class="info">
          {{ detailsItem.startTime }} ~ {{ detailsItem.endTime }} 召开民主测评会，应到{{
            detailsItem.sumPerson
          }}人次，实到{{ detailsItem.actuallyPerson }}人次。
        </div>
      </div>
      <div class="search_line" v-if="peopleType.length > 1">
        <van-radio-group v-model="type" direction="horizontal" @change="onChange">
          <van-radio :name="item.value" v-for="item in peopleType" :key="item.value">{{ item.text }}</van-radio>
        </van-radio-group>
      </div>
      <div class="table">
        <table v-if="detailsItem.resultVOS.length > 0">
          <thead>
            <tr>
              <th>序号</th>
              <th>姓名</th>
              <th>好</th>
              <th>较好</th>
              <th>一般</th>
              <th>较差</th>
              <th>弃权</th>
              <th>总(实投/应投)</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(item, index) in detailsItem.resultVOS" :key="item.id">
              <td>{{ index + 1 }}</td>
              <td>{{ item.userName }}</td>
              <td style="width: 10%">{{ item.level_1 }}</td>
              <td>{{ item.level_2 }}</td>
              <td>{{ item.level_3 }}</td>
              <td>{{ item.level_4 }}</td>
              <td>{{ item.level_no }}</td>
              <td>{{ item.level_ed }} / {{ item.level_sum }}</td>
            </tr>
          </tbody>
        </table>
        <van-empty description="暂无签到" v-else />
      </div>
    </template>
    <van-empty description="暂无数据" v-else />
  </div>
</template>

<script>
import { listAssessmentResult, listAssessmentResultOrgan, getNoCivilNeedAssessByOrgId } from '@api/api-democratic.js'

export default {
  name: 'resultTable',
  components: {},
  props: {
    searchParams: Object,
  },
  data() {
    return {
      id: this.$route.query.id,
      detailsItem: {
        resultVOS: [],
      },
      peopleType: [],
      userInfo: JSON.parse(localStorage.userInfo),
      type: 2,
    }
  },
  computed: {
    searchParamsTypeName() {
      if (this.searchParams.type == 1) {
        return '领导'
      } else if (this.searchParams.type == 2) {
        return '非领导'
      } else if (this.searchParams.type == 5) {
        return '非公务员'
      }
    },
  },
  watch: {
    searchParams: {
      handler(newVal, oldVal) {
        if (!this.id) {
          this.initdata1()
        }
      },
      immediate: true,
      deep: true,
    },
  },
  created() {},
  mounted() {
    if (!this.id) {
      this.initdata1()
    } else {
      this.initdata(2)
      this.getNoCivilNeedAssessByOrgId()
    }
  },
  methods: {
    initdata(type) {
      listAssessmentResult({
        assessmentId: this.id,
        type: type,
      })
        .then(res => {
          const data = res.data
          data.resultVOS = data.resultVOS ? data.resultVOS : []
          this.detailsItem = data
        })
        .catch(err => {
          this.finished = true
        })
    },
    /* 组织部数据查询 */
    initdata1() {
      if (!this.searchParams.title || !this.searchParams.id) return
      listAssessmentResultOrgan({
        assessmentId: this.id,
        orgId: this.searchParams.id,
        title: this.searchParams.title,
        type: this.searchParams.type,
        tenantId: this.searchParams.tenantId,
      }).then(res => {
        let data = res.data
        data.resultVOS = data.resultVOS ? data.resultVOS : []
        this.detailsItem = { ...data }
        setTimeout(() => {
          if (this.$refs.downHeader) {
            this.$nextTick(() => {
              this.height = this.$refs.sectionCon.offsetHeight - this.$refs.downHeader.offsetHeight - 90
            })
          }
        }, 100)
      })
    },
    getNoCivilNeedAssessByOrgId() {
      getNoCivilNeedAssessByOrgId({
        oneParam: this.userInfo.loginPostInfo.orgId,
      }).then(res => {
        if (res.status === 200) {
          if (res.data.length > 0) {
            this.peopleType = [
              { text: '非领导成员', value: 2 },
              { text: '非公务员', value: 5 },
            ]
          } else {
            this.peopleType = [{ text: '非领导成员', value: 2 }]
          }
        }
      })
    },
    onChange() {
      this.initdata(this.type)
    },
  },
}
</script>

<style lang="scss" scoped>
.desc {
  text-align: center;
  // font-size: 14px;
  margin-top: 15px;
  .big_title {
    font-size: 16px;
    font-weight: bold;
  }
  .little_title {
    font-weight: bold;
    margin-top: 8px;
  }
  .info {
    color: #666;
    margin-top: 10px;
  }
}
.table {
  margin-top: 15px;
  margin-bottom: 10px;
  // font-size: 14px;
  table {
    width: 100%;
    border-right: 1px solid #eeeeee;
    border-top: 1px solid #eeeeee;
    thead {
      background-color: #f2f2f2;
    }
    th,
    td {
      // flex: 1;
      text-align: center;
      padding: 8px 1px;
      border-left: 1px solid #eeeeee;
      border-bottom: 1px solid #eeeeee;
      font-size: 13px;
    }
  }
}
.search_line {
  margin-top: 15px;
  // font-size: 14px;
  /deep/.van-radio {
    margin-right: 12px;
  }
}
</style>
